package breeze.pixel.weather.apps_util.utils.appsettings.settingsview;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;

import com.google.android.material.card.MaterialCardView;

import breeze.pixel.weather.BaseView;
import breeze.pixel.weather.R;
import breeze.pixel.weather.apps_util.utils.AppToolUtil;
import breeze.pixel.weather.apps_util.utils.MDialog;

public class ChangeWeatherIcon extends BaseView {

    private RadioButton niwuhua,bianpinghua,xaingsuhua;
    private int type = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        setContentView(R.layout.activity_change_weather_icon);
        init();
        initData();
    }

    @Override
    public void init() {
        flatten = find(R.id.materialCardView5);
        pixile = find(R.id.materialCardView7);
        reality = find(R.id.materialCardView6);
    }

    @Override
    public void initData() {
        if (sets.getIconType() == 0){
            focus(flatten);
            remove(reality);
            remove(pixile);
        }else if (sets.getIconType() == 1){
            focus(reality);
            remove(flatten);
            remove(pixile);
        }else{
            focus(pixile);
            remove(reality);
            remove(flatten);
        }
    }

    public void save(View view) {
        sets.setIconType(type);
        MDialog dialog = new MDialog(this);
        dialog.setTitle("提示");
        dialog.setMessage("需要重新启动APP");
        dialog.setPositiveButton("立即重启", () -> AppToolUtil.reStartApp(ChangeWeatherIcon.this));
        dialog.setNegativeBotton("稍后重启", this::finish);
        dialog.show();
    }

    public MaterialCardView flatten;
    public MaterialCardView reality;
    public MaterialCardView pixile;

    private void focus(MaterialCardView materialCardView) {
        materialCardView.setStrokeWidth(10);
        materialCardView.setStrokeColor(Color.parseColor("#339933"));
    }

    private void remove(MaterialCardView cardView) {
        cardView.setStrokeWidth(5);
        cardView.setStrokeColor(Color.parseColor("#f1f1f1"));
    }

    public void flatten(View view) {
        type = 0;
        MaterialCardView materialCardView = (MaterialCardView) view;
        focus(materialCardView);
        remove(reality);
        remove(pixile);
    }

    public void reality(View view) {
        type = 1;
        MaterialCardView materialCardView = (MaterialCardView) view;
        focus(materialCardView);
        remove(flatten);
        remove(pixile);
    }

    public void pixile(View view) {
        type = 2;
        MaterialCardView materialCardView = (MaterialCardView) view;
        focus(materialCardView);
        remove(reality);
        remove(flatten);
    }
}